package leagal_aid.bean;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import leagal_aid.bean.Page;
import leagal_aid.util.DBUtil;

//类名
public class LawBean {
	//属性（成员变量）
		private int id;
		private String title;
		private int homepage;
		private Date time;
		private String link;
		private String category;
		private String content;		
		private String categoryname;

        
	
		PreparedStatement statement=null;
		ResultSet rs = null;
		Connection connection = null;
		public int getId() {
			return id;
		}
		public void setId(int id) {
			this.id = id;
		}
		public String getTitle() {
			return title;
		}
		public void setTitle(String title) {
			this.title = title;
		}
		public int getHomepage() {
			return homepage;
		}
		public void setHomepage(int homepage) {
			this.homepage = homepage;
		}
		public Date getTime() {
			return time;
		}
		public void setTime(Date time) {
			this.time = time;
		}
		public String getLink() {
			return link;
		}
		public void setLink(String link) {
			this.link = link;
		}
		public String getCategory() {
			return category;
		}
		public void setCategory(String category) {
			this.category = category;
		}
		public String getContent() {
			return content;
		}
		public void setContent(String content) {
			this.content = content;
		}
		public String getCategoryname() {
			return categoryname;
		}
		public void setCategoryname(String categoryname) {
			this.categoryname = categoryname;
		}
				//查询全部内容
				public List<LawBean> findAll() {
					List<LawBean> list = new ArrayList<LawBean>();
					DBUtil dbUtil = new DBUtil();
					String sql = "select * from law";
					connection = dbUtil.geConnection();
					try {
						statement = connection.prepareStatement(sql);
						rs = statement.executeQuery();
						while(rs.next()) {
							LawBean lawBean = new LawBean();
							lawBean.setId(rs.getInt("id"));
							lawBean.setTitle(rs.getString("title"));
							lawBean.setCategory(rs.getString("Category"));
							lawBean.setTime(rs.getDate("time"));
							lawBean.setHomepage(rs.getInt("homepage"));
							lawBean.setContent(rs.getString("content"));
							lawBean.setLink(rs.getString("link"));
							lawBean.setCategoryname(rs.getString("Categoryname"));

							list.add(lawBean);
						}
						
					} catch (SQLException e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}
					return list;
					
				}

				//通过ID查找
						public LawBean findLawById(int id) {
							
							DBUtil dbUtil = new DBUtil();
							connection = dbUtil.geConnection();
							LawBean lawBean = new LawBean();
							try {
								String sql = "select * from law where id = ?";
								statement = connection.prepareStatement(sql);
								statement.setInt(1, id);
								rs = statement.executeQuery();
								
								if(rs.next()) {
									lawBean.setId(rs.getInt("id"));
									lawBean.setTitle(rs.getString("title"));
									lawBean.setCategory(rs.getString("Category"));
									lawBean.setTime(rs.getDate("time"));
									lawBean.setHomepage(rs.getInt("homepage"));
									lawBean.setContent(rs.getString("content"));	
									lawBean.setCategoryname(rs.getString("Categoryname"));
									lawBean.setLink(rs.getString("link"));

								}
								
							} catch (SQLException e) {
								e.printStackTrace();
							}finally {
								if (rs != null) {
									try {
										rs.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if (statement != null) {
									try {
										statement.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if(connection != null) {
									try {
										connection.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								dbUtil.close();
							}

							return lawBean;
							
						}
				
						//通过类别查找
						public List<LawBean> finddwgzByLb(String lbString) {
							List<LawBean> list = new ArrayList<LawBean>();
							DBUtil dbUtil = new DBUtil();
							connection = dbUtil.geConnection();
							String sql = "select * from law where category =?";
							try {
								statement = connection.prepareStatement(sql);
								statement.setString(1, lbString);
								rs = statement.executeQuery();
								while(rs.next()) {
									LawBean lawBean = new LawBean();
									lawBean.setId(rs.getInt("id"));
									lawBean.setTitle(rs.getString("title"));
									lawBean.setCategory(rs.getString("Category"));
									lawBean.setTime(rs.getDate("time"));
									lawBean.setHomepage(rs.getInt("homepage"));
									lawBean.setContent(rs.getString("content"));
									lawBean.setCategoryname(rs.getString("Categoryname"));
									lawBean.setLink(rs.getString("link"));
									list.add(lawBean);
								}


							} catch (SQLException e) {
								e.printStackTrace();
							}finally {
								if (rs != null) {
									try {
										rs.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if (statement != null) {
									try {
										statement.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if(connection != null) {
									try {
										connection.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								dbUtil.close();
							}
							return list;
							
						}
				
						//增加页面内容
						public boolean doAdd(String category,String title,Integer homepage,String txtDate,String link,String content,String categoryname) {
							boolean add = false;
							DBUtil dbUtil = new DBUtil();
							connection = dbUtil.geConnection();
							//String sql = "select password from admin where username = " + username + "'";
							String sql = "insert into law(category,title,homepage,time,link,content,categoryname) values(?,?,?,?,?,?,?)";
							
						  try {		
							  PreparedStatement statement = connection.prepareStatement(sql);
								statement.setString(1, category);
								statement.setString(2, title);
								statement.setInt(3, homepage);
								statement.setString(4, txtDate);
								statement.setString(5, link);
								statement.setString(6, content);
								statement.setString(7, categoryname);
								System.out.println(add);
								int i = statement.executeUpdate();
								if (i>0) {
									add = true;
								}
									
							} catch (SQLException e) {
								e.printStackTrace();
							}finally {
								if (rs != null) {
									try {
										rs.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if (statement != null) {
									try {
										statement.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if(connection != null) {
									try {
										connection.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								dbUtil.close();
							}
							return add;
							
						}
						
						//修改内容
						public boolean doUpdata(String category,String title,Integer homepage,String txtDate,String link,String content,String categoryname,int id) {
							boolean updata = false;
							DBUtil dbUtil = new DBUtil();
							connection = dbUtil.geConnection();
							//String sql = "select password from admin where username = " + username + "'";
							String sql = "update law set category =?,title =?,homepage =?,time=?,link=?,content=?,categoryname=? where id =?";
							try {
								PreparedStatement statement = connection.prepareStatement(sql);
								statement.setString(1, category);
								statement.setString(2, title);
								statement.setInt(3, homepage);
								statement.setString(4, txtDate);
								statement.setString(5, link);
								statement.setString(6, content);
								statement.setString(7, categoryname);
								
								statement.setInt(8, id);
								System.out.println(updata);
								int i = statement.executeUpdate();
								if (i>0) {
									updata = true;
								}
									
							} catch (SQLException e) {
								e.printStackTrace();
							}finally {
								if (rs != null) {
									try {
										rs.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if (statement != null) {
									try {
										statement.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if(connection != null) {
									try {
										connection.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								dbUtil.close();
							}
							return updata;
							
						}
						
						
						//删除内容
						public boolean doDel(int id) {
							boolean del = false;
							DBUtil dbUtil = new DBUtil();
							connection = dbUtil.geConnection();
							String sql = "delete from  law where id =?";
							//String sql = "insert into sfgk(v1,v2) values(?,getdate());";
						    //String sql = "insert into sfgk(category,title,source,content,author,id) values(?,?,?,?,?,?)";
							
						  try {		
							  PreparedStatement statement = connection.prepareStatement(sql);
						
								statement.setInt(1, id);
								int i = statement.executeUpdate();
								if (i>0) {
									del = true;
								}
									
							} catch (SQLException e) {
								e.printStackTrace();
							}finally {
								if (rs != null) {
									try {
										rs.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if (statement != null) {
									try {
										statement.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if(connection != null) {
									try {
										connection.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								dbUtil.close();
							}
							return del;
							
						}
						
						//放在首页的方法
						public List<LawBean> findOnindex() {
							List<LawBean> list = new ArrayList<LawBean>();
							DBUtil dbUtil = new DBUtil();
							String sql = "select * from law where homepage=1  order by time desc ";
							connection = dbUtil.geConnection();
							try {
								statement = connection.prepareStatement(sql);
								rs = statement.executeQuery();
								while(rs.next()) {
									LawBean lawBean = new LawBean();
									lawBean.setId(rs.getInt("id"));
									lawBean.setTitle(rs.getString("title"));
									lawBean.setCategory(rs.getString("Category"));
									lawBean.setTime(rs.getDate("time"));
									lawBean.setHomepage(rs.getInt("homepage"));
									lawBean.setContent(rs.getString("content"));
									lawBean.setCategoryname(rs.getString("Categoryname"));
									lawBean.setLink(rs.getString("link"));
									list.add(lawBean);
								}
								
							} catch (SQLException e) {
								e.printStackTrace();
							}finally {
								if (rs != null) {
									try {
										rs.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if (statement != null) {
									try {
										statement.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if(connection != null) {
									try {
										connection.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								dbUtil.close();
							}
							return list;
							
						}
						
						//通过时间排序
						public List<LawBean> findAllByLbForPX(String lbString) {
							System.out.println("run findAllByLb " + lbString);
							List<LawBean> list = new ArrayList<LawBean>();
							DBUtil dbUtil = new DBUtil();
							connection = dbUtil.geConnection();
							String sql = "select * from law where category = ?  order by time desc";
							try {
								statement = connection.prepareStatement(sql);
								statement.setString(1, lbString);
								rs = statement.executeQuery();
								while (rs.next()) {
									LawBean lawBean = new LawBean();
									lawBean.setId(rs.getInt("id"));
									lawBean.setTitle(rs.getString("title"));
									lawBean.setCategory(rs.getString("Category"));
									lawBean.setTime(rs.getDate("time"));
									lawBean.setHomepage(rs.getInt("homepage"));
									lawBean.setLink(rs.getString("link"));
									lawBean.setContent(rs.getString("content"));
									lawBean.setCategoryname(rs.getString("Categoryname"));
									list.add(lawBean);
									System.out.println("findAllByLb  " + lawBean);
								}
								
							} catch (Exception e) {
								e.printStackTrace();
							}finally {
								if (rs != null) {
									try {
										rs.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if (statement != null) {
									try {
										statement.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if(connection != null) {
									try {
										connection.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								dbUtil.close();
							}
							return list;
							
						}
						
						//前端类别查找
						public List<LawBean> findAllByLb(String lbString) {
							List<LawBean> list = new ArrayList<LawBean>();
							DBUtil dbUtil = new DBUtil();
							connection = dbUtil.geConnection();
							String sql = "select * from law where category =?  order by time desc";
							try {
								statement = connection.prepareStatement(sql);
								statement.setString(1, lbString);
								rs = statement.executeQuery();
								while(rs.next()) {
									LawBean lawBean = new LawBean(); 
									lawBean.setCategory(rs.getString("category"));
									lawBean.setId(rs.getInt("id"));
									lawBean.setTitle(rs.getString("title"));
									lawBean.setTime(rs.getDate("time"));
									lawBean.setLink(rs.getString("link"));
									lawBean.setContent(rs.getString("content"));
									lawBean.setCategoryname(rs.getString("Categoryname"));
									list.add(lawBean);
								}
								
							} catch (SQLException e) {
								e.printStackTrace();
							}finally {
								if (rs != null) {
									try {
										rs.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if (statement != null) {
									try {
										statement.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if(connection != null) {
									try {
										connection.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								dbUtil.close();
							}
							return list;
							
						}

						//后端页面通过类别查找
						public List<LawBean> findbackByLb(String lbString) {
							List<LawBean> list = new ArrayList<LawBean>();
							DBUtil dbUtil = new DBUtil();
							connection = dbUtil.geConnection();
							String sql = "select * from law where category =?";
							try {
								statement = connection.prepareStatement(sql);
								statement.setString(1, lbString);
								rs = statement.executeQuery();
								while(rs.next()) {
									LawBean lawBean = new LawBean(); 
									lawBean.setCategory(rs.getString("category"));
									lawBean.setId(rs.getInt("id"));
									lawBean.setTitle(rs.getString("title"));
									lawBean.setTime(rs.getDate("time"));
									lawBean.setLink(rs.getString("link"));
									lawBean.setContent(rs.getString("content"));
									lawBean.setCategoryname(rs.getString("Categoryname"));
									list.add(lawBean);
								}
								
							} catch (SQLException e) {
								e.printStackTrace();
							}finally {
								if (rs != null) {
									try {
										rs.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if (statement != null) {
									try {
										statement.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if(connection != null) {
									try {
										connection.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								dbUtil.close();
							}
							return list;
							
						}
						
						
						//总数查询
						public int findCountByLb(String lbString) {
							DBUtil dbUtil = new DBUtil();
							connection = dbUtil.geConnection();
							int count = 0;
							String sql = "select count(*) totalCount from law where category =?";
							try {
								statement = connection.prepareStatement(sql);
								statement.setString(1, lbString);
								rs = statement.executeQuery();
								if (rs.next()) {
									count=rs.getInt("totalCount");
								}
								
							} catch (SQLException e) {
								e.printStackTrace();
							}finally {
								if (rs != null) {
									try {
										rs.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if (statement != null) {
									try {
										statement.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if(connection != null) {
									try {
										connection.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								dbUtil.close();
							}
							return count;
							
						}


						//分页
						public List<LawBean> findAllByLbForFY(String lbString,Page page) {
							List<LawBean> list = new ArrayList<LawBean>();
							DBUtil dbUtil = new DBUtil();
							connection = dbUtil.geConnection();
							String sql = "select * from law where category =? order by time desc limit ?,? ";
							try {
								statement = connection.prepareStatement(sql);
								statement.setString(1, lbString);
								statement.setInt(2, page.getBeginIndex());
								statement.setInt(3, page.getEveryPage());
								rs = statement.executeQuery();
								while(rs.next()) {
									LawBean lawBean = new LawBean();
									lawBean.setId(rs.getInt("id"));
									lawBean.setTitle(rs.getString("title"));
									lawBean.setCategory(rs.getString("Category"));
									lawBean.setTime(rs.getDate("time"));
									lawBean.setHomepage(rs.getInt("homepage"));
									lawBean.setContent(rs.getString("content"));
									lawBean.setCategoryname(rs.getString("Categoryname"));
									lawBean.setLink(rs.getString("link"));
									list.add(lawBean);
								}
								
							} catch (SQLException e) {
								e.printStackTrace();
							}finally {
								if (rs != null) {
									try {
										rs.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if (statement != null) {
									try {
										statement.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if(connection != null) {
									try {
										connection.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								dbUtil.close();
							}
							return list;
							
						}
						//查找上一页的ID
						public LawBean findPreNewsById(List<LawBean> listLawBean, int id) {
							LawBean dwgzBean = null;
							for(int i=0;i<listLawBean.size();i++) {
								if(id == listLawBean.get(i).getId()&&i!=0) {
									dwgzBean = listLawBean.get(i-1);
									return dwgzBean;
								}
							}
							return dwgzBean;
							 
							}

		            //查找下一页的ID
						public LawBean findNextNewsById(List<LawBean> listLawBean,int id) {
							LawBean lawBean = null;
							for(int i=0;i<listLawBean.size();i++) {
								if(id == listLawBean.get(i).getId()&&i+1<listLawBean.size()) {
									lawBean = listLawBean.get(i+1);
									return lawBean;
								}
							}
							return lawBean;
							 
							 
							}
						
						public LawBean findPreNewsById(int id) {
							System.out.println("run findNewsByid  nad ib");
							DBUtil dbUtil = new DBUtil();
							connection = dbUtil.geConnection();
							LawBean lawBean = new LawBean();
							String sql = "select * from law where id < ?order by id desc limit 1 ";
							try {
								statement = connection.prepareStatement(sql);
								statement.setInt(1, id);
								System.out.println(sql);
								rs = statement.executeQuery();
								System.out.println(sql);
								
								if(rs.next()) {
									lawBean.setId(rs.getInt("id"));
									lawBean.setTitle(rs.getString("title"));
									lawBean.setCategory(rs.getString("Category"));
									lawBean.setTime(rs.getDate("time"));
									lawBean.setHomepage(rs.getInt("homepage"));
									lawBean.setContent(rs.getString("content"));
									lawBean.setCategoryname(rs.getString("Categoryname"));
									lawBean.setLink(rs.getString("link"));

									
								}
								
							} catch (SQLException e) {
								e.printStackTrace();
							}finally {
								if (rs != null) {
									try {
										rs.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if (statement != null) {
									try {
										statement.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if(connection != null) {
									try {
										connection.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								dbUtil.close();
							}

							return lawBean;
							
						}
						
						
						
						
						public LawBean findNextNewsById( int id) {
							
							DBUtil dbUtil = new DBUtil();
							connection = dbUtil.geConnection();
							LawBean lawBean = new LawBean();
							String sql = "select * from law where id > ? and homepage=1 order by id asc limit 1 ";
							try {
								
								statement = connection.prepareStatement(sql);
								statement.setInt(1, id);
								System.out.println(sql);
								rs = statement.executeQuery();
								System.out.println(sql);
								if(rs.next()) {
									lawBean.setId(rs.getInt("id"));
									lawBean.setTitle(rs.getString("title"));
									lawBean.setCategory(rs.getString("Category"));
									lawBean.setTime(rs.getDate("time"));
									lawBean.setHomepage(rs.getInt("homepage"));
									lawBean.setContent(rs.getString("content"));
									lawBean.setCategoryname(rs.getString("Categoryname"));
									lawBean.setLink(rs.getString("link"));
								}
								
							} catch (SQLException e) {
								e.printStackTrace();
							}finally {
								if (rs != null) {
									try {
										rs.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if (statement != null) {
									try {
										statement.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								if(connection != null) {
									try {
										connection.close();
									} catch (SQLException e) {
										e.printStackTrace();
									}
								}
								dbUtil.close();
							}

							return lawBean;
							
						}
						
						
					
						
						

						
						
				
						//分页查询
						 public int findbackCountByLb(String lbString) {
						 	DBUtil dbUtil = new DBUtil();
						 	connection = dbUtil.geConnection();
						 	int count = 0;
						 	String sql = "select count(*) totalCount from law where category =? ";
						 	try {
						 		statement = connection.prepareStatement(sql);
						 		statement.setString(1, lbString);
						 		rs = statement.executeQuery();
						 		if (rs.next()) {
						 			count=rs.getInt("totalCount");
						 		}
						 		
						 	} catch (SQLException e) {
						 		e.printStackTrace();
						 	}finally {
						 		if (rs != null) {
						 			try {
						 				rs.close();
						 			} catch (SQLException e) {
						 				e.printStackTrace();
						 			}
						 		}
						 		if (statement != null) {
						 			try {
						 				statement.close();
						 			} catch (SQLException e) {
						 				e.printStackTrace();
						 			}
						 		}
						 		if(connection != null) {
						 			try {
						 				connection.close();
						 			} catch (SQLException e) {
						 				e.printStackTrace();
						 			}
						 		}
						 		dbUtil.close();
						 	}
						 	return count;
						 	
						 }


						 //后端模糊查询后总数
						 public int findselectCountByLb(String lbString,String tilString) {
						 	DBUtil dbUtil = new DBUtil();
						 	connection = dbUtil.geConnection();
						 	int count = 0;
						 	String sql = "select count(*) totalCount from law where category =? and concat(id,title,category,time,link) like ? ";
						 	try {
						 		statement = connection.prepareStatement(sql);
						 		statement.setString(1, lbString);
						 		statement.setString(2,"%" + tilString + "%");
						 		rs = statement.executeQuery();
						 		if (rs.next()) {
						 			count=rs.getInt("totalCount");
						 			System.out.print("totalCount :"+count);
						 		}
						 		
						 	} catch (SQLException e) {
						 		e.printStackTrace();
						 	}finally {
						 		if (rs != null) {
						 			try {
						 				rs.close();
						 			} catch (SQLException e) {
						 				e.printStackTrace();
						 			}
						 		}
						 		if (statement != null) {
						 			try {
						 				statement.close();
						 			} catch (SQLException e) {
						 				e.printStackTrace();
						 			}
						 		}
						 		if(connection != null) {
						 			try {
						 				connection.close();
						 			} catch (SQLException e) {
						 				e.printStackTrace();
						 			}
						 		}
						 		dbUtil.close();
						 	}
						 	return count;
						 	
						 }

						 //后端分页
						 public List<LawBean> findbackByLbForFY(String lbString,Page page) {
						 	List<LawBean> list = new ArrayList<LawBean>();
						 	DBUtil dbUtil = new DBUtil();
						 	connection = dbUtil.geConnection();
						 	String sql = "select * from law where category =? order by time desc limit ?,? ";
						 	try {
						 		statement = connection.prepareStatement(sql);
						 		statement.setString(1, lbString);
						 		statement.setInt(2, page.getBeginIndex());
						 		statement.setInt(3, page.getEveryPage());
						 		rs = statement.executeQuery();
						 		while(rs.next()) {
						 			LawBean lawBean = new LawBean();
						 			   lawBean.setId(rs.getInt("id"));
						 			   lawBean.setTitle(rs.getString("title"));
						 			   lawBean.setCategory(rs.getString("category"));
						 			   lawBean.setTime(rs.getDate("time"));
						 			   lawBean.setLink(rs.getString("link"));
						 			   lawBean.setHomepage(rs.getInt("homepage"));
										lawBean.setContent(rs.getString("content"));
										lawBean.setCategoryname(rs.getString("Categoryname"));
						 			list.add(lawBean);
						 		}
						 		
						 	} catch (SQLException e) {
						 		e.printStackTrace();
						 	}finally {
						 		if (rs != null) {
						 			try {
						 				rs.close();
						 			} catch (SQLException e) {
						 				e.printStackTrace();
						 			}
						 		}
						 		if (statement != null) {
						 			try {
						 				statement.close();
						 			} catch (SQLException e) {
						 				e.printStackTrace();
						 			}
						 		}
						 		if(connection != null) {
						 			try {
						 				connection.close();
						 			} catch (SQLException e) {
						 				e.printStackTrace();
						 			}
						 		}
						 		dbUtil.close();
						 	}
						 	return list;
						 	
						 }
						 //模糊查询
						 public List<LawBean> Proselect(String lbString,String tilString,Page page) {
						 	    List<LawBean> list =new ArrayList<LawBean>();
						 	    DBUtil dbUtil = new DBUtil();
						 	    connection = dbUtil.geConnection();
						 	    //String sql = "select * from news";
						 	    String sql ="select * from law where category =? and concat(id,title,category,time,link,homepage) like ? order by time desc limit ?,?" ;
						 	    connection = dbUtil.geConnection();
						 	    try {
						 	     statement = connection.prepareStatement(sql);
						 	     statement.setString(1, lbString);
						 	     statement.setString(2,"%" + tilString + "%");
						 	     statement.setInt(3, page.getBeginIndex());
						 	     statement.setInt(4, page.getEveryPage());
						 	     rs = statement.executeQuery();
						 	     while(rs.next()) {
						 	    	   LawBean lawBean = new LawBean();
						 			   lawBean.setId(rs.getInt("id"));
						 			   lawBean.setTitle(rs.getString("title"));
						 			   lawBean.setCategory(rs.getString("category"));
						 			   lawBean.setTime(rs.getDate("time"));
						 			   lawBean.setLink(rs.getString("link"));
						 			   lawBean.setHomepage(rs.getInt("homepage"));
										lawBean.setContent(rs.getString("content"));
										lawBean.setCategoryname(rs.getString("Categoryname"));
						 			   list.add(lawBean);
						 	     }
						 	     
						 	    } catch (SQLException e) {
						 	     e.printStackTrace();
						 	    }finally {
						 	     if (rs != null) {
						 	      try {
						 	       rs.close();
						 	      } catch (SQLException e) {
						 	       e.printStackTrace();
						 	      }
						 	     }
						 	     if (statement != null) {
						 	      try {
						 	       statement.close();
						 	      } catch (SQLException e) {
						 	       e.printStackTrace();
						 	      }
						 	     }
						 	     if(connection != null) {
						 	      try {
						 	       connection.close();
						 	      } catch (SQLException e) {
						 	       e.printStackTrace();
						 	      }
						 	     }
						 	     dbUtil.close();
						 	    }
						 	    return list;
						 	    
						 	   }
				
						 //前端首页获取类别
						 public  List<LawBean> findOnIndexbylb() {
								List<LawBean> list = new ArrayList<LawBean>();
								
								DBUtil dbUtil = new DBUtil();
								String sql = "select * from law where homepage=1 order by time desc ";
								
								connection = dbUtil.geConnection();
								try {
									statement = connection.prepareStatement(sql);
									System.out.println(statement.toString());
									rs = statement.executeQuery();
									while(rs.next()) {
										LawBean lawBean = new LawBean();
										lawBean.setId(rs.getInt("id"));
										lawBean.setTitle(rs.getString("title"));
										lawBean.setCategory(rs.getString("category"));
										lawBean.setLink(rs.getString("link"));
										lawBean.setContent(rs.getString("content"));
										lawBean.setCategoryname(rs.getString("Categoryname"));
										list.add(lawBean);
										System.out.println(rs.getString("title"));
									}
									
								} catch (SQLException e) {
									e.printStackTrace();
								}finally {
									if (rs != null) {
										try {
											rs.close();
										} catch (SQLException e) {
											e.printStackTrace();
										}
									}
									if (statement != null) {
										try {
											statement.close();
										} catch (SQLException e) {
											e.printStackTrace();
										}
									}
									if(connection != null) {
										try {
											connection.close();
										} catch (SQLException e) {
											e.printStackTrace();
										}
									}
									dbUtil.close();
								}
								return list;
								
							}


		
				
				
				
				
}
